<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  
  <title>SSH利用public key登录 | Wentao&#39;s Blog</title>

  
  <meta name="author" content="wentao">
  

  
  <meta name="description" content="ssh作为是远程管理linux服务器的一个很重要的手段.一般的情况下使用账户和密码可以登录的.但是这种方式不太方便也不太安全.比方如果用rsync同步的时候,如果做成自动的话,每次还要输入密码.这个就不太方便了.这个时候如果可以直接登录多方便.
ssh是可以使用密钥登录的.把生成的公钥文件传到服务器">
  

  
  
  <meta name="keywords" content="linux">
  

  <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <meta property="og:title" content="SSH利用public key登录"/>

  <meta property="og:site_name" content="Wentao&#39;s Blog"/>

  
  <meta property="og:image" content="/favicon.ico"/>
  

  <link href="/favicon.ico" rel="icon">
  <link rel="alternate" href="/atom.xml" title="Wentao&#39;s Blog" type="application/atom+xml">
  <link rel="stylesheet" href="/css/style.css" media="screen" type="text/css">
</head>


<body>
<div class="blog">
  <div class="content">

    <header>
  <div class="site-branding">
    <h1 class="site-title">
      <a href="/">Wentao&#39;s Blog</a>
    </h1>
    <p class="site-description"></p>
  </div>
  <nav class="site-navigation">
    <ul>
      
        <li><a href="/">主页</a></li>
      
        <li><a href="/archives">归档</a></li>
      
    </ul>
  </nav>
</header>

    <main class="site-main posts-loop">
    <article>

  
    
    <h3 class="article-title"><span>SSH利用public key登录</span></h3>
    
  

  <div class="article-top-meta">
    <span class="posted-on">
      <a href="/2014/01/17/ssh-with-public-key/" rel="bookmark">
        <time class="entry-date published" datetime="2014-01-17T08:42:00.000Z">
          2014-01-17
        </time>
      </a>
    </span>
  </div>


  

  <div class="article-content">
    <div class="entry">
      
        <p><code>ssh</code>作为是远程管理linux服务器的一个很重要的手段.一般的情况下使用账户和密码可以登录的.但是这种方式不太方便也不太安全.比方如果用<code>rsync</code>同步的时候,如果做成自动的话,每次还要输入密码.这个就不太方便了.这个时候如果可以直接登录多方便.</p>
<p><code>ssh</code>是可以使用密钥登录的.把生成的公钥文件传到服务器上面就可以.</p>
<p><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">ssh-keygen</div><div class="line">ssh-copy-id -i ~/.ssh/id_rsa.pub  root@192.168.1.100</div></pre></td></tr></table></figure></p>
<p>如果没有<code>ssh-copy-id</code>的话,需要用下面的命令来手动执行了.
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">ssh root@192.168.1.100 <span class="string">"mkdir .ssh;chmod 0700 .ssh"</span>  (需要输入密码)</div><div class="line">scp ~/.ssh/id_rsa.pub root@192.168.1.100:.ssh/id_rsa.pub  (需要输入密码)</div></pre></td></tr></table></figure></p>
<p>以上就可以完成使用密钥的方式远程登录了.不过如果生成的时候没有指定用id_rsa的话,则需要在登录的时候指定具体使用那个密钥.</p>

      
    </div>

  </div>

  <div class="article-footer">
    <div class="article-meta pull-left">

    
      

    <span class="post-categories">
      <i class="icon-categories"></i>
        <a href="/categories/Dev/">Dev</a>
    </span>
    

    
    

    <span class="post-tags">
      <i class="icon-tags"></i>
        <a href="/tags/linux/">linux</a>
    </span>
    

    </div>

    
  </div>
</article>

  
	<div id="comment">
	
	
	<!-- 多说评论框 start -->
	 <div class="ds-thread" data-thread-key="/2014/01/17/ssh-with-public-key/" data-title="SSH利用public key登录" data-url="http://wentao.org/2014/01/17/ssh-with-public-key/"></div>
	<!-- 多说评论框 end -->
	<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
	<script type="text/javascript">
	var duoshuoQuery = {short_name:"wentao"};
	  (function() {
	    var ds = document.createElement('script');
	    ds.type = 'text/javascript';ds.async = true;
	    ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
	    ds.charset = 'UTF-8';
	    (document.getElementsByTagName('head')[0] 
	     || document.getElementsByTagName('body')[0]).appendChild(ds);
	  })();
	  </script>
	<!-- 多说公共JS代码 end -->
	
	</div>




    </main>

    <footer class="site-footer">
  <p class="site-info">
    Proudly powered by <a href="https://hexo.io/" target="_blank">Hexo</a> and
    Theme by <a href="https://github.com/CodeDaraW/Hacker" target="_blank">Hacker</a>
    </br>
    
    &copy; 2016 wentao
    
  </p>
</footer>
    
  </div>
</div>
</body>
</html>